package com.example.exercise.analysis.visit.service.impl;

import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

import com.example.exercise.analysis.visit.dto.request.UserLoginRequest;
import com.example.exercise.analysis.visit.dto.response.UserLoginResponse;
import com.example.exercise.analysis.visit.mapper.entity.UserLoginEntity;
import com.example.exercise.analysis.visit.service.UserLoginService;
import com.example.exercise.analysis.visit.mapper.UserLoginMapper;

@Service
public class UserLoginServiceImpl implements UserLoginService {

	@Resource
	private UserLoginMapper userLoginMapper;

	@Override
	public List<UserLoginResponse> findByWhere(UserLoginRequest userLoginRequest){
		List<UserLoginResponse> list = new ArrayList<>();
		userLoginRequest.setBegin((userLoginRequest.getCurrentPage() - 1) * userLoginRequest.getPageSize());
		List<UserLoginEntity> list0 = userLoginMapper.findByWhere(userLoginRequest);
		for (UserLoginEntity userLoginEntity : list0) {
			UserLoginResponse userLoginResponse = new UserLoginResponse();
			BeanUtils.copyProperties(userLoginEntity,userLoginResponse);
			list.add(userLoginResponse);
		}
		return list;
	}

	@Override
	public Integer getCountByWhere(UserLoginRequest userLoginRequest){
		return userLoginMapper.getCountByWhere(userLoginRequest);
	}

	@Override
	public UserLoginResponse findById(Integer id){
		UserLoginResponse userLoginResponse = new UserLoginResponse();
		UserLoginEntity userLoginEntity = userLoginMapper.findById(id);
		BeanUtils.copyProperties(userLoginEntity,userLoginResponse);
		return userLoginResponse;
	}

	@Override
	public int insertUserLogin(UserLoginRequest userLoginRequest){
		UserLoginEntity userLoginEntity = new UserLoginEntity();
		BeanUtils.copyProperties(userLoginRequest,userLoginEntity);
		return userLoginMapper.insertUserLogin(userLoginEntity);
	}

	@Override
	public int updateUserLogin(UserLoginRequest userLoginRequest){
		UserLoginEntity userLoginEntity = new UserLoginEntity();
		BeanUtils.copyProperties(userLoginRequest,userLoginEntity);
		return userLoginMapper.updateUserLogin(userLoginEntity);
	}

	@Override
	public int deleteById(Integer id){
		return userLoginMapper.deleteById(id);
	}

}